#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int n, x[N], y[N], z[N], a[N], b[N], P[N], Q[N];

int upd(int x) { return x + (x >> 31 & mod); }
ll qp(ll x, int t) { ll res = 1; for(; t; t >>= 1, x = x * x % mod) if(t & 1) res = res * x % mod; return res; }

void solve() {
	n = in; rep(i, 1, n) x[i] = in, y[i] = in, z[i] = in;
	P[n] = 1ll * upd(-x[1]) * qp(y[1], mod - 2) % mod;
	Q[n] = 1ll * z[1] * qp(y[1], mod - 2) % mod;
	per(i, n, 2) {
		P[i - 1] = upd(1ll * P[i] * x[i] % mod + 1ll * P[n] * y[i] % mod - mod);
		P[i - 1] = P[i - 1] * qp(y[i], mod - 2) % mod;
		Q[i - 1] = upd(1ll * Q[i] * x[i] % mod + 1ll * Q[n] * y[i] % mod - mod);
		Q[i - 1] = upd(Q[i - 1] - z[i]);
		Q[i - 1] = Q[i - 1] * qp(y[i], mod - 2) % mod;
	}
	if(P[1] == 1 && Q[1]) puts("0");
	else if(P[1] == 1 && Q[1] == 0) printf("%d\n", mod);
	else {
		a[1] = b[1] = Q[1] * qp(upd(1 - P[1]), mod - 2) % mod;
		rep(i, 2, n) b[i] = upd(1ll * P[i] * a[1] % mod + Q[i] - mod);
		rep(i, 2, n) a[i] = upd(b[i] - b[i - 1]);
		puts("1");
		rep(i, 1, n) printf("%d ", a[i]);
		puts("");
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	for(int T = in; T; T--) solve();
	return 0;
}
